// @ts-ignore
/* eslint-disable */

/**
 * 该文件为 @umijs/openapi 插件自动生成，请勿随意修改。如需修改请通过配置 openapi.config.ts 进行定制化。
 * */

import { request, type RequestOptions } from '@/utils/request';

/** 检查切片 GET /tools/upload/check */
export async function uploadCheckChunks(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.UploadCheckChunksParams,
  options?: RequestOptions
) {
  return request<any>('/tools/upload/check', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 切片上传 POST /tools/upload/chunk */
export async function uploadUploadChunk(
  body: API.FileUploadChunkDto,
  chunk?: File,
  options?: RequestOptions
) {
  const formData = new FormData();

  if (chunk) {
    formData.append('chunk', chunk);
  }

  Object.keys(body).forEach(ele => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach(f => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<string>('/tools/upload/chunk', {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}

/** 切片下载 GET /tools/upload/file-chunk */
export async function uploadDownChunks(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.UploadDownChunksParams,
  options?: RequestOptions
) {
  return request<any>('/tools/upload/file-chunk', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 合并切片 POST /tools/upload/merge */
export async function uploadUploadChunkMerge(
  body: API.FileUploadChunkMergeDto,
  options?: RequestOptions
) {
  return request<any>('/tools/upload/merge', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 上传 POST /tools/upload/single */
export async function uploadUpload(
  body: API.FileUploadDto,
  file?: File,
  options?: RequestOptions
) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach(ele => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach(f => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<any>('/tools/upload/single', {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}
